//2024.03.27 23:15 星期三 雨 里宸光 喜欢
/**
 * @author 林公子
 * @version 1.0.0
 * @file 这个文件 作用于 avanda 的 解构
 */

import { avandaTaskObj } from '../../../../../testComps/avanda/avandaUnitObj/avandaUnitObj';
import { ObjectOnlyPushSet } from '../../global';
let tasksName = 'tasksName';

function signAvanda(name, that) {
  if (window.Avanda == undefined) {
    createMainAvanda();
  }
  window.Avanda.sign_obj(name, that);
}

function createMainAvanda() {
  window.Avanda = new avandaTaskObj('main', 'main Avanda');
  //   let a = window.Avanda;
  //   a.changetoMainAvanda = changetoMainAvanda;
  //   a.changetoMainAvanda();
  //   delete a.changetoMainAvanda;
  changetoMainAvanda.call(window.Avanda);
}

function changetoMainAvanda() {
  let a = {
    data: ['tasksName', 'sign_obj', 'get_task'],
    tasksName: [],
    sign_obj: sign_obj,
    get_task: get_task,
  };
  this.extendAvanda('main', a);
  this.shrinkAvanda(['task', 'prop']);
}

function sign_obj(name, obj) {
  ObjectOnlyPushSet(this, name, obj, tasksName);
}

/**
 *
 * @param {string} str task 的 名称
 * @returns 对应的 task | main avanda 摘录
 */
function get_task(str) {
  if (str == undefined) {
    return excerpt_main_avadanda(this);
  }
  return this[str];
}

function excerpt_main_avadanda(main_that) {
  let b = { tasksName: [] };
  for (let i = 0; i < main_that[tasksName].length; i++) {
    ObjectOnlyPushSet(
      b,
      main_that[tasksName][i],
      main_that[main_that[tasksName][i]],
      tasksName
    );
  }
  return b;
}

export { signAvanda };
